package com.link510.aitools.activity.airobot.core;

import android.content.Intent;
import android.os.Bundle;

import com.blankj.utilcode.util.ToastUtils;
import com.link510.aitools.R;
import com.link510.aitools.core.listen.CWMListener;
import com.link510.aitools.core.message.MessageInfo;
import com.link510.aitools.framework.activity.BaseAcitivity;
import com.link510.aitools.services.Airobots;
import com.link510.aitools.services.CustomWaitDialogUtils;

import butterknife.OnClick;

public class RobotCoreActivity extends BaseAcitivity {

    private CustomWaitDialogUtils customWaitDialogUtils;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_robot_coreboard);
        customWaitDialogUtils = new CustomWaitDialogUtils(RobotCoreActivity.this);
    }

    /**
     * 修改设备名称
     */
    @OnClick(R.id.name_edit_button)
    public void nameEditButtonClick() {
        Intent intent = new Intent(RobotCoreActivity.this, RobotCoreEditNameActivity.class);
        startActivity(intent);
    }


    /**
     * 修改IP地址
     */
    @OnClick(R.id.ip_edit_button)
    public void ipEditButtonClick() {
        Intent intent = new Intent(RobotCoreActivity.this, RobotCoreEditIPActivity.class);
        startActivity(intent);
    }

    /**
     * 修改IP地址
     */
    @OnClick(R.id.upgrade_button)
    public void upgradeButtonClick() {
        Intent intent = new Intent(RobotCoreActivity.this, RobotCoreUpgradeActivity.class);
        startActivity(intent);
    }

    /**
     * 日志收集
     */
    @OnClick(R.id.logs_button)
    public void logsGetButtonClick() {

        customWaitDialogUtils.show("命令下发中...");

        Airobots.getInstance().logsGet(this.deviceSN, new CWMListener<MessageInfo<String>>() {
            @Override
            public void onSuccess(String message, MessageInfo<String> stringMessageInfo) {
                customWaitDialogUtils.close();
                ToastUtils.showShort("命令下发成功");
            }

            @Override
            public void onError(int code, String message) {
                customWaitDialogUtils.close();
                ToastUtils.showShort("命令下发失败");
            }
        });
    }

    /**
     * 重启设备
     */
    @OnClick(R.id.reboot_button)
    public void rebootButtonClick() {

        customWaitDialogUtils.show("命令下发中...");

        Airobots.getInstance().reboot(this.deviceSN, new CWMListener<MessageInfo<String>>() {
            @Override
            public void onSuccess(String message, MessageInfo<String> stringMessageInfo) {
                customWaitDialogUtils.close();
                ToastUtils.showShort("命令下发成功");
            }

            @Override
            public void onError(int code, String message) {
                customWaitDialogUtils.close();
                ToastUtils.showShort("命令下发失败");
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        customWaitDialogUtils.dismiss();
    }
}